home *** CD-ROM | disk | FTP | other *** search
/ Your Choice 3 / Your Choice Software Collection 3.iso / dos / secdr13d / fpart.c < prev    next >
C/C++ Source or Header  |  1994-04-20  |  4KB  |  181 lines

  1. /* Secure Drive FPART V1.3d */
  2. /* Finds (possible) Partition boot records */
  3.  
  4. #include "secdrv.h"
  5.  
  6. int  tsr_not_installed;
  7. int  tsr_wrong_version;
  8. void setrldb(void far *real_dbios_vect);
  9.  
  10. unsigned char *buf;
  11. int invalid_boot=0;
  12.  
  13. void main()
  14. {
  15. unsigned drive,firstcyl,firsthead;
  16. unsigned cyl,head,sector,maxcyl,endcyl,maxhead,maxsector,secsize,t;
  17. unsigned i,hdx;
  18. unsigned serial[2];
  19.  
  20. char drvltr,r;
  21.  
  22. clrscr();
  23.  
  24.  
  25. if(!(buf=malloc(512))) {
  26.     printf("Error: unable to allocate memory for sector buffer.\n");
  27.     exit(1); }
  28.  
  29.  
  30. printf("\
  31. Secure Drive Find Partition Utility Version 1.3d \n\
  32. \n\
  33. This program searches a physical hard disk for boot records.\n");
  34.  
  35. gettsradr();
  36.  
  37. if(tsr_wrong_version)
  38.  {
  39.   printf ("ERROR: Wrong Version (not 1.3D) of SECTSR is Installed\n");
  40.   exit(1);
  41.  }
  42.  
  43. if (tsr_not_installed)
  44.   printf("Warning: SECTSR not installed.\n");
  45.  
  46. askdrive:
  47. printf("Enter Physical Drive Number (0,1,2,...) to Scan: ");
  48. while(!isdigit(drvltr=toupper(getch())));
  49. printf("%c\n",drvltr);
  50.  
  51.  
  52. drive=drvltr-'0';
  53. printf("\n\
  54. If you don't know how many Cylinders are on this drive, just enter a\n\
  55. high value, e.g. 20000, and Abort when read errors are reported after\n\
  56. running off the end.\n\n\
  57. Enter number of Cylinders to scan : ");
  58. scanf("%u",&endcyl);
  59. drive+=0x80;
  60.  
  61. for (firstcyl=0;firstcyl<endcyl;firstcyl++)
  62.  {
  63.   for(firsthead=0;firsthead<2;firsthead++)
  64.    {
  65.     readsec(drive,firsthead,firstcyl,1,1,buf);
  66.     if((buf[510]==0x55)&&(buf[511]==0xaa))
  67.      {
  68.       calcdiskparams(buf,&maxcyl,&maxhead,&maxsector,
  69.                      &secsize,serial);
  70.       if (!invalid_boot && (secsize & 511) == 0)
  71.        {
  72.         printf("\nPossible partition found on \
  73. physical hard drive %u, at cylinder %u, head %u\n",
  74.                drive-0x80,firstcyl,firsthead);
  75.  
  76.         printf("This partition has \
  77. %u cylinders, %u sectors, %u heads, sector size %u bytes\n\n",
  78.                maxcyl+1,maxsector,maxhead,secsize);
  79.  
  80.        printf("Continue to Scan? ");
  81.        if(!getyn())
  82.            {
  83.            printf("\n");
  84.            exit(0);
  85.            }
  86.  
  87.        } /*if !invalid_boot*/
  88.      } /* if boot sector*/
  89.    } /*for firsthead*/
  90.  } /*for firstcyl*/
  91.  
  92. printf("End of Scan\n");
  93. exit(0);
  94. }
  95.  
  96. struct tsrdata far *gettsradr(void)
  97. {
  98. unsigned seg;
  99. unsigned ofs;
  100. struct tsrdata far *ptr;
  101. struct REGPACK rgs;
  102.  
  103. rgs.r_ax=0x0800;
  104. rgs.r_dx=0x00f0;
  105. intr(0x13,&rgs);
  106. if(rgs.r_ax==0x0edcb)
  107.  {
  108.   tsr_wrong_version=1;
  109.   return( (struct tsrdata far *) NULL);
  110.  }
  111. if(rgs.r_ax!=0x0edcc)
  112.  {
  113.   tsr_not_installed=1;
  114.   return( (struct tsrdata far *) NULL);
  115.  }
  116. /* ptr=(long) rgs.r_dx+(long) 0x10000*rgs.r_cx; */
  117. ptr = MK_FP(rgs.r_cx,rgs.r_dx);
  118. if (memcmp(ptr->tsrver,"130C",4) != 0)
  119.  {
  120.   tsr_wrong_version=1;
  121.   return( (struct tsrdata far *) NULL);
  122.  }
  123. setrldb(&ptr->real_dbios_vect);
  124. return(ptr);
  125. }
  126.  
  127. void calcdiskparams(unsigned char *buf,unsigned *maxtrack,
  128.                     unsigned *maxhead,unsigned *maxsector,
  129.                     unsigned *secsize,unsigned serial[2])
  130. {
  131. unsigned long i,l0,l1,l2,l3;
  132.  
  133. invalid_boot=0;
  134. *maxsector=buf[0x18]+256*buf[0x19];
  135. *maxhead=buf[0x1a]+256*buf[0x1b];
  136. *secsize=buf[0x0b]+256*buf[0x0c];
  137. serial[0]=buf[0x27]+256*buf[0x28];
  138. serial[1]=buf[0x29]+256*buf[0x2a];
  139. l0=(unsigned char)buf[0x20];
  140. l1=(unsigned char)buf[0x21];
  141. l2=(unsigned char)buf[0x22];
  142. l3=(unsigned char)buf[0x23];
  143. i=l0+256*(l1+256*(l2+256*(l3)));
  144. if(i==0) i=(unsigned)buf[0x13]+256*buf[0x14];
  145. if (*maxsector == 0 || *maxhead == 0)
  146.  {
  147.   invalid_boot=1;
  148.   return;
  149.  }
  150. *maxtrack=i / *maxsector / *maxhead;
  151. if((i%(*maxsector * *maxhead))==0) (*maxtrack)--;
  152. }
  153.  
  154. void readsec(unsigned drive,unsigned head,unsigned track,
  155.              unsigned sector,unsigned nsects,void *buffer)
  156. {
  157. unsigned i;
  158. char c;
  159. for(;;) {
  160.     for(i=0;i<3;i++)
  161.         if(!rldbios(2,drive,head,track,sector,nsects,buffer)) return;
  162.     printf("\nRead error: drive %02x, head %u, track %u\n",
  163.             drive,head,track);
  164.     printf("Abort, Retry, Ignore? ");
  165.     c=toupper(getch()); printf("%c\n",c);
  166.     if(c=='I') return;
  167.     if(c=='A') exit(1);
  168.     }
  169. }
  170.  
  171. int getyn(void)
  172. {
  173. char c;
  174. for(;;)
  175.     {
  176.     c=getch();
  177.     if(c=='y'||c=='Y') { printf("Yes\n\n"); return(TRUE); }
  178.     if(c=='n'||c=='N') { printf("No\n\n"); return(FALSE); }
  179.     }
  180. }
  181.